﻿using System;
using System.Collections.Generic;
using System.Linq;
using ZHDJ.Core;
using ZHDJ.Data;
using ZHDJ.Data.DataCaching;
using ZHDJ.WebPage;
using ZHDJ.WebPage.Master;

namespace ZHDJ.Web.PortalParts
{
    public partial class PageMorePartyRepresentative : MorePageMaster
    {
        /// <summary>
        /// 工作室ID
        /// </summary>
        private string StudioID
        {
            get
            {
                return this.Request["StudioID"] ?? "";
            }
        }

        public string ImgUrl { get; set; }
        public string StudioName { get; set; }

        protected void Page_Load(object sender, EventArgs e)
        {

            LoadData();

        }

        /// <summary>
        /// 加载
        /// </summary>
        public void LoadData()
        {
            using (var DB = new DBInstance().DB)
            {
                var studio = DB.PartyRepresentativeStudios.Find(StudioID);
                if (studio == null)
                {
                    //Response.Redirect("~/default.aspx");
                    RedirectToDefault();
                }
                this.litStudioName.Text= studio.StudioName;
                ImgUrl = studio.ImageID;
            }
            imgStudio.ImageUrl= UpFileBusiness.GetFileUrl(ImgUrl);
            var moduleQuery = PartyModuleNavigationCaching.Get(SysEnum.PartyRepresentative);
            var m = moduleQuery.FirstOrDefault(a => string.IsNullOrEmpty(a.Category));
            if (m == null)
            {
                //Response.Redirect("~/default.aspx");
                RedirectToDefault();
            }
            ModuleName = m.PageName;
            var q = moduleQuery.Where(a => a.Enabled && !string.IsNullOrEmpty(a.Category));
          
            rptPage.DataSource = q.ToList();
            rptPage.DataBind();
            hdCategory.Value = Category;
        }

        public string GetUrl(string url)
        {
            var temp = url;
            if (temp.IndexOf('?') > 0)
            {
                temp = temp + "&StudioID=" + this.StudioID;
            }
            else
            {
                temp = temp + "?StudioID=" + this.StudioID;
            }
            return temp;
        }

    }
}